const pageTo = (url, param) => {
	const rootUrl = ['/pages/goods/list','/pages/type/type','/pages/cart/cart','/pages/mine/mine']
	if(rootUrl.includes(url)) uni.reLaunch({url})
	console.log(url,"去到的地址");
	if (url === -1) {
		return uni.navigateBack()
	}
	if (param == 'redirect') {
		return uni.redirectTo({
			url
		})
	}
	uni.navigateTo({
		url
	})
}
const message = (text = '', time = 2000, i = 'none') => {
	return new Promise((resolve, reject) => {
		uni.showToast({
			title: text,
			icon: i,
			mask: true,
			success: () => {
				const timer = setTimeout(() => {
					clearTimeout(timer)
					resolve()
				}, time)
			}
		})
	})
}
const loading = (text = '', mask = true) => {
	uni.showLoading({
		title: text,
		mask: mask
	})
}
const hideLoading = () => {
	uni.hideLoading()
}
let timer = 0
const throttle = (fn, wait = 500) => {
	if (!timer) {
		timer = setTimeout(() => {
			fn()
			clearTimeout(timer)
			timer = null
		}, wait)
	}
}
const debounce = (fn, wait = 1000) => {
	console.log(`${wait/1000}秒后准备emo`);
	if (timer) {
		console.log('有内鬼，任务取消');
		console.log("------------");
		clearTimeout(timer)
		timer = null
	}
	timer = setTimeout(() => {
		fn()
		console.info('到点了，emo');
	}, wait)
}


export default {
	pageTo,
	message,
	loading,
	hideLoading,
	throttle,
	debounce
}
